-- 获取前20条输赢记录
ALTER PROCEDURE [dbo].[CPP_User_HistoryData]
  @dwUserID INT, -- 用户ID
  @dwKindID INT
AS
BEGIN

  SELECT TOP 20
    a.UserID,
    a.dwRoomID AS RoomID,
    a.dwKindID AS KindID,
    b.UserDate,
    a.InsertTime,
    b.InsertTime AS InsertTime2
  FROM
    RYRecordDB.dbo.PrivateGameRecordUserRecordID AS a
  LEFT JOIN RYRecordDB.dbo.RoomNumberAllRecord AS b ON a.dwRoomID = b.RoomID AND a.dwKindID = b.kindID
  AND DATEDIFF(
    HH,
    b.InsertTime,
    a.InsertTime
  ) = 0
  WHERE
    (a.UserID = @dwUserID AND a.dwKindID = @dwKindID)
  ORDER BY
    a.InsertTime DESC

	RETURN 0
END